import 'package:dio/dio.dart';
import 'package:flutter_changdian_football/api/api.dart';
import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/http_utils.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class ReqAli {

  /// 获取支付配置信息
  static Future<ApiResponse<dynamic>> getPayProperties() async {
    try {
      var response = await HttpUtils.post(Api.getPayProperties);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 支付宝授权获取用户支付宝信息
  static Future<ApiResponse<dynamic>> zfbAuthorization({
    required String authCode
  }) async {
    try {
      var response = await HttpUtils.post(Api.zfbAuthorization, data: {
        'authCode': authCode
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 支付宝提现到个人
  static Future<ApiResponse<dynamic>> zfbWithdraw({
    String? clubId,
    String? reason,
    required String withdrawAmount,
    required String withdrawType
  }) async {
    try {
      var response = await HttpUtils.post(Api.zfbWithdraw, data: {
        "clubId": clubId,
        "reason": reason,
        "withdrawAmount": withdrawAmount,
        "withdrawType": withdrawType
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 支付宝支付（充值）
  static Future<ApiResponse<dynamic>> zfbPay({
    required String businessType,
    String? clubId,
    required String payAmount
  }) async {
    try {
      var response = await HttpUtils.post(Api.zfbPay, data: {
        "businessType": businessType,
        "clubId": clubId ?? '',
        "payAmount": payAmount,
        "paymentType": 'APP'
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

}